<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增需求列')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-requirement-add">
            <input type="hidden" name="projectId" id="projectId" th:value="${project.projectId}"/>
            <div class="form-group">
                <label class="col-sm-3 control-label">当前项目：</label>
                <div class="form-control-static" th:text="'&nbsp;&nbsp;&nbsp;&nbsp;' + ${project.projectName}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">提出时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="beginTime" id="beginTime" class="form-control"  type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">需求分类：</label>
                <div class="col-sm-8">
                    <select name="reqType" class="form-control m-b" th:with="type=${@dict.getType('sys_req_type')}">
                        <option value="">-请选择-</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">优先级：</label>
                <div class="col-sm-8">
                    <select name="reqPri" class="form-control m-b" th:with="type=${@dict.getType('sys_req_pri')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>需求内容：</label>
                <div class="col-sm-8">
                    <textarea name="reqContent" id="reqContent" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>计划工作量：</label>
                <div class="col-sm-8">
                    <input name="planDays" id="planDays" class="form-control" type="text" >
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">

        var prefix = ctx + "system/requirement"
        $("#form-requirement-add").validate({
            focusCleanup: true,
            rules:{
                reqContent:{required:true,maxlength:250},
                planDays:{required:true,number:true },
                beginTime:"required"

            },
            messages:{
                reqContent:{
                    required:"请输入内容",
                    maxlength:"不能超过250个字"
                },
                beginTime:"请填入时间",
                planDays:"请输入正确数字"

            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-requirement-add').serialize());
            }
        }
        $("input[name='beginTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            endDate: new Date(),
            autoclose: true
        });
        $("input[name='endTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        //自动生成编号；格式：yyMM0001
        function createCode() {
                var a="";
                $.ajax({
                    async : false,
                    cache : false,
                    type : 'POST',
                    contentType : 'application/json',
                    dataType:"json",
                    url : "/system/requirement/createCode",
                    error : function() {
                        alert('出错了');
                        frameElement.api.close();
                    },
                    success : function(code) {
                        a=code.attributes.msg;
                    }
                });
                $("#createCode").val(a);
        }

        function sTime() {
            var t= new Date();
            var y=t.getFullYear();
            var d=t.getMonth()+1;
            var m=t.getDate();
            return y+"-"+d+"-"+m;
        }
        document.getElementById("beginTime").value=sTime();
        /*var verifyUtils={
            isInteger:function (idStr) {
                var str=document.getElementById("planDays").value.trim();
                var regex="/^[1-9]\\d*$/";
                if(!regex.test(str)){
                    alert("请输入正确的数值！");
                 }
                }
            }*/

    </script>
</body>
</html>